
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author luisrocha
 */
public class MySqlDBConnection {

    public static Connection Connect (String localhost, String database)
    {
              
        Connection DBConn = null;       // MySQL connection handle
        try 
        {
            //load JDBC driver class for MySQL
            Class.forName( "com.mysql.jdbc.Driver" );
        
        } catch (ClassNotFoundException ex) 
        
        {
            Logger.getLogger(MySqlDBConnection.class.getName()).log(Level.SEVERE, null, ex);
        } //end try-catch

        //define the data source
        String SQLServerIP = localhost;
        String sourceURL = "jdbc:mysql://" + SQLServerIP + ":3306/"+ database;
       
        try 
        {
            //create a connection to the db - note the default account is "remote"
            //and the password is "remote_pass" - you will have to set this
            //account up in your database

            DBConn = DriverManager.getConnection(sourceURL,"remote","remote_pass");

        } catch (SQLException ex) 
        {
            Logger.getLogger(MySqlDBConnection.class.getName()).log(Level.SEVERE, null, ex);
        } //end try-catch
        
        return DBConn;
    } // end MySqlDBConnection
    
}
